package com.groupseven.happycampus.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.groupseven.happycampus.common.pojo.Commodity;
import com.groupseven.happycampus.common.pojo.OwnCommodity;
import com.groupseven.happycampus.common.result.R;
import com.groupseven.happycampus.common.vo.LayuiPageVo;
import com.groupseven.happycampus.mapper.OwnCommodityMapper;
import com.groupseven.happycampus.service.OwnCommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service(value = "ownCommodityService")
public class OwnCommodityServiceImpl implements OwnCommodityService {

    @Autowired
    private OwnCommodityMapper ownCommodityMapper;

    @Override
    public LayuiPageVo<OwnCommodity> ownCommodityListPageData(Map<String, Object> params) {

        //设置分页查询的内容
        int limit = Integer.parseInt(params.get("limit").toString());
        int page = Integer.parseInt(params.get("page").toString());
        PageHelper.startPage(page,limit);

        List<OwnCommodity>ownCommodities =  ownCommodityMapper.selectOwnCommodityList(params);

        PageInfo<OwnCommodity> ownCommodityPageInfo = new PageInfo<>(ownCommodities);

        LayuiPageVo<OwnCommodity> ownCommodityLayuiPageVo = new LayuiPageVo<>();
        ownCommodityLayuiPageVo.setCode(0);
        ownCommodityLayuiPageVo.setMsg("个人仓库商品展示");
        ownCommodityLayuiPageVo.setCount(ownCommodityPageInfo.getTotal());
        ownCommodityLayuiPageVo.setData(ownCommodityPageInfo.getList());
        return ownCommodityLayuiPageVo;
    }

    @Override
    public int addCommodity(Commodity commodity) {
        return ownCommodityMapper.addCommodity(commodity);
    }


}
